package com.linkage.bss.crm.packagemgr.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.linkage.bss.commons.dao.Page;
import com.linkage.bss.commons.dao.ibatis.BaseDAO;
import com.linkage.bss.crm.packagemgr.dao.IPackageStatusDAO;
import com.linkage.bss.crm.packagemgr.model.Channel;

/**
 * 状态管理dao 接口
 *
 * @author  Administrator
 * @version  [版本号, 2013-5-9]
 * @see  [相关类/方法]
 * @since  [产品/模块版本]
 */
public class PackageStatusDAOImpl extends BaseDAO implements IPackageStatusDAO {

	/**
	 * 注释内容
	 */
	private static final long serialVersionUID = 4616102858702188390L;

	/**
	 * 根据促销活动Id更新活动状态
	 * @param activityId
	 */
	public void updatePackageStatus(Long packageId, Integer statusCD) {

		Map<String, Object> updateMap = new HashMap<String, Object>();
		updateMap.put("statusCd", statusCD);
		updateMap.put("packageId", packageId);
		getSqlMapClientTemplate().update("PackageStatus.updatePackageStatus", updateMap);
	}

	public void savePackage2Area(Map<String, Object> map) {
		getSqlMapClientTemplate().insert("PackageStatus.savePackage2Area", map);
	}

	public void savePackage2Channel(Map<String, Object> map) {
		getSqlMapClientTemplate().insert("PackageStatus.savePackage2Channel", map);
	}

	public void delPackage2Area(Long packageID) {
		getSqlMapClientTemplate().delete("PackageStatus.delPackage2Area", packageID);

	}

	public void delPackage2Channel(Long packageID) {
		getSqlMapClientTemplate().delete("PackageStatus.delPackage2Channel", packageID);
	}

	public void insertOPLog(Long packageID, Long staffID, Integer op) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("packageId", packageID);
		map.put("partyID", staffID);
		map.put("operateType", op);
		getSqlMapClientTemplate().insert("PackageStatus.insertPackageLog", map);
	}

	public Channel getChannelByID(Integer channelId) {
		return (Channel) getSqlMapClientTemplate().queryForObject("PackageStatus.getChannelByID", channelId);
	}

	/**
	 * 查询包发布的渠道数
	 * @param map
	 * @return
	 */
	public List<Channel> queryPackage2Channel(Long packageId) {
		return getSqlMapClientTemplate().queryForList("PackageStatus.queryPackage2Channel", packageId);
	}

	public List<Channel> getChannelByName(Map map, Page queryPage) {
		return queryForPageList("PackageStatus.getChannelByName", map, queryPage);
	}

	public int getChannelByNameCount(Map map) {
		return (Integer) getSqlMapClientTemplate().queryForObject("PackageStatus.getChannelByNameCount", map);
	}

}
